<?php
namespace app\madmin\controller;
use app\madmin\model\SystemBackupModel;

/**
 * 备份控制器
 * @author  黄明杰 vx:HMJ125855
 * @version 20190101
 */
class SystemBackup extends PublicBase{

    # 备份列表方法
    public function showList(){
        $SystemBackup = new SystemBackupModel;

        $Where = $this->getFormWhere();

        $Lists = $SystemBackup->mList($Where, '*', config('CNF_LISTPAGE'));

        return $this->fetch('SystemBackup/showList', [
            'Lists' => $Lists
        ]);
    }

    # 备份添加方法
    public function showAdd(){
        $SystemBackup = new SystemBackupModel;

        if(request()->isPost()){
            $Param = input('post.');

            $Back = $SystemBackup->mAdd($Param);

            $this->ShowData($Back['code'], $Back['msgs'], $Back['urls']);
        }else{
            return $this->fetch('SystemBackup/showAdd', [
                'Table' => $SystemBackup->mTables()
            ]);
        }
    }

    # 备份还原方法
    public function showEdit(){
        if(request()->isPost()){
            $SystemBackup = new SystemBackupModel;

            $ID = input('post.id');

            $Back = $SystemBackup->mEdit(['backup_id'=>$ID]);

            $this->ShowData($Back['code'], $Back['msgs']);
        }
    }

    # 备份下载方法
    public function showFile(){
        if(request()->isGet()){
            $SystemBackup = new SystemBackupModel;

            $ID = input('param.id');

            $SystemBackup->mFile(['backup_id'=>$ID]);
        }
    }

    # 备份删除方法
    public function showDel(){
        if(request()->isPost()){
            $SystemBackup = new SystemBackupModel;

            $ID = input('post.id');

            $Back = $SystemBackup->mDel(['backup_id'=>$ID]);

            $this->ShowData($Back['code'], $Back['msgs']);
        }
    }

}